package com.gxgeek.spring.security.securitycore.validate.code.sms;

import com.gxgeek.spring.security.securitycore.properties.SecurityProperties;
import com.gxgeek.spring.security.securitycore.validate.code.ValidateCode;
import com.gxgeek.spring.security.securitycore.validate.code.ValidateCodeGenerator;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * @author gaoxing
 * @create 2017-10-18 下午3:16
 */
@Component("smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {
    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode generatorCode(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
        return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
    }
}
